const qs = require('qs')
const dateFormat = require('../../../../src/utils/dateFormat')
const ERR_CODE = 0
let ID = 1

const photo = {
	idImage: '/upload/identity/SDF2342341341234/陈正华.jpg',
	idNum: '350322199609171535',
	name: '刘点徐',
	nation: '汉族',
	registerAddress: '福建省莆田市'
}

let time = new Date().getTime()

const allList = Array.from({ length: 300 }).map((v, i) => {
	const { year, month, day, hour, minute, second } = dateFormat(time)
	const createTime = `${year}-${month}-${day} ${hour}:${minute}:${second}`
	time -= Math.random() * 10 * 24 * 60 * 60 * 1000
	const status = [0, 2, 5][Math.floor(Math.random() * 3)]

	return {
		...photo,
		id: ID++,
		createTime,
		status
	}
})

module.exports = function (app) {
	app.post('/api/admin/scan/photoList', (req, res) => {
		const { page, limit, orderby } = qs.parse(req.query)
		const list = allList.slice((page - 1) * limit, page * limit)

		if (orderby === 'createTime') {
		} else {
			list.forEach((v, i) => {
				v.status =
					i < page * limit + i < 50 ? 2 : page * limit + i < 100 ? 0 : 5
			})
		}
		setTimeout(() => {
			res.json({
				code: ERR_CODE,
				data: {
					list,
					totalRow: allList.length
				}
			})
		}, 1500)
	})
}
